{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 15.1. Diving into symbolic computing with SymPy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy import *\n",
    "init_printing()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "podoc": {
     "output_text": "(x, y)"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQQAAABTBAMAAACL2mTCAAAAMFBMVEX///92dnaIiIhUVFSYmJgi\nIiJERES6urpmZmYQEBDMzMwyMjLc3Nzu7u6qqqoAAAA1ApXJAAAAAXRSTlMAQObYZgAAAAlwSFlz\nAAAOxAAADsQBlSsOGwAABeVJREFUaN7FWr9vI0UUHjte55ftuAEJmliiorIbKpCciorIpysOCk52\ne0jgVFA6/AU2QoBOutOmpzAlDbJFd0LCFugE15D0gJw43sQbJ3m8nd2ZnZndkNXsanea2Lve8Zv3\n3ve9772YELb+JamuQvDSL7fpmjD5Tr2yZR6m7AU4Ua70LkjKq76Q31fgh7RN2ICq7AR7mrYJpCu5\noQTXqVtADDgQ3r2EvfRNkM/dvCAZrLrlv85nEQdCtsEngkkWcXAicenn5opksvq2T1SX2ZhwzCOx\nmT4vMXZiOVgP0HVKqwzn3gvTIhmtJhzRvzlYZGVCDzpeKtxkZYLhJUMPGlmZkIelywpZZaOTjzCl\nf2yS2WpTXs4zZGSxdmk+GtkBgpAhhcIwmzLprh16/joMsjOhSLOgG8Bk6fX2t/v0xWvwKBG0vG9+\nfRB6IwcOM5uqWNjqgg1U3u7CU4BafAu+x338nH/7QlTuiMoSgGJgy/qA/An4uaK9T9aby9gWrMN7\npMXrck48FX77CYoFmCoVdI9mSIM0sYYX2l4liZP2t07eXXFpIOg1jMEhWVOZafeZ+8HbnEVrmdJx\naFCguedA/4KrRDHyXXiA92TVVrDHri+s4TWNVewKsnZO0cdO2gLRr304xXsyOU4uvQICT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zyyxyFThS5ZFp\nc/0WKc82NCtlixW4Agi1wL2w4GZG+v/Yq1NdJHrl8ZUKf4ObVIrWRfc1AdFmWripKo6Wb1I9SjKU\ndH9rMvLqWz5Qas2loGoiUO+2rpBtwkPvzHNVpz/3D2hGyLS+boXoDZgc2lNmcWLf2ru/YSlo/+an\neOE8WerCx2qSzCV03FuBeleaFqD6Ozsiv3YDXVtO/tL+vf97+Xusa4LTQuH6SvXibKUwmLYujLB+\nQ7HwZlDTPleQk/IP/VBPWlO1/z5K14Jy+6cA5p6la4IR/DVX5cOU48CT7z89+mzk5fNvdgAAAABJ\nRU5ErkJggg==\n",
      "text/plain": [
       "(x, y)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "var('x y')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "x, y = symbols('x y')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "expr1 = (x + 1) ** 2\n",
    "expr2 = x**2 + 2 * x + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr1 == expr2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "podoc": {
     "output_text": "0"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAACQAAAA5BAMAAACsZpTuAAAAMFBMVEX///+qqqoiIiLc3NxmZmaI\niIgQEBDu7u66urpEREQyMjJUVFR2dnaYmJjMzMwAAABcNhdRAAAAAXRSTlMAQObYZgAAAAlwSFlz\nAAAOxAAADsQBlSsOGwAAAY1JREFUOMuNlLtOAkEUhkdBUcTF2gbfwC1tjJR2kvgAUlu4xFYTaa12\ne030DdbOhGatjB08gIm+gSC6ogv8zpy57O5ggtPMzMdwrv9Zxmg5z52rJ5Zd5x74Sl5TsgTsuzuP\nSFqalELci/0IJxqdYkz7CrCh0Dbq8uBjKg9reFe/VRC7dKhhok0AAe0emhp1MRLbOvCg0Z60sQy0\nNeJnEe4bYGIugpwfGIeURp+8fBu0AAwo5MQghy4VqHQoWwgrq8BnWhNeopbwO8mhNrsgi3rxUjZ4\n9jp9WRTc8aQtFPBSWmiLJ49hikLwskQ26v+Fbmz0NR/RLZyH6PZv81MLRXaOfd6gGTRTiSZ7sdGt\nqOooV+hA9H+Qa0edVe0O9Vg520feWrii2x9ZAYCUkZPJj5ZBKqaxTCsruSHNBMyclEWkTIiip1FV\nnotCBkyPB/2jIPVJK1Ixdk2sJaipWETcMg7lCBSMMd+895WAHegpZI4nn9Uy2j5DfMjYJuJ2WqZL\nnqiHuJH9Kux2vONr9eYXXYNOUewc7uIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "0"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "simplify(expr1 - expr2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "podoc": {
     "output_text": "Output"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAACoBAMAAADJB1PKAAAAMFBMVEX///8yMjJUVFR2dnZERERm\nZmbMzMzc3NwQEBCIiIgiIiKYmJiqqqq6urru7u4AAAAC7oxIAAAAAXRSTlMAQObYZgAAAAlwSFlz\nAAAOxAAADsQBlSsOGwAAC+5JREFUeNrtXU2II8cV1v+/evZi7IvRHnKOfAuEgCY34xjL5GAScug5\nhGwuQTKGOJgk2mDIxk5Iz8EHhxw0e4ghGEdDiAP5AS0hCSYZosFgJwcbTSCQZQ6W529Ho5nZZ6n1\nM93q96q7qlU1vWq9y2glrdT9qeq97733VVUksrKJffAE3P3SCgabvQkjO6mvkLiyV+DX//7BFwHO\nVlDMLAVvjf68B7C+AmNq3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Dq4lFvVpTe7BNW/E+pwVgatSIYktC\n7dGNLcXn6CSBuaKJ8DhppTuP5lWfoxNlL++tELGpCQqPmsuoPoVqjb0rRo1oQkVV7hqvq9r+ye2u\nr3JoNAlIG+rOF0gp36ixze4yxagWcVfdGdM5OacGsAntHtPHET9TXs5RGKhfU75tv4vWhpad6Kp2\nZC0oP/TCVRLcoso7CVWDuqbazY5qt2wvViFTo9KFmp/N+I3q2RN12zuyQepaYmqOLdk/UD1QLLIS\nGjXKo+p3lDi9ddWYjCLyrgvFJtOcwjsqZs9ryjFxP/pEA7iIhMzchZ7lYB23p8A8nCnRBXXcNRiW\ndJenZkJy1qst+LjdcTxQZx6psKZ7mVyDcByVbCXx7mVyPWSetuhFO94ImadNeBF3x0LmaRtetlVI\ng59e26Nn3txFOUhHm0o3zdtxYLWAHnskx+Le1ouEy6n0vMUVLVROpeyxz9eWdIp1EC3ldQTkQsRU\nol4XFqWCehShBOt4XhmhB/QwNSmJj9fNQu/DICSYZL2vVSxIO/MveBzfeztSD9Shr1Jnj/eD/KIh\nmT9JnkWt/GulH03rcu3b2Q1Fo0MzuJr5WVDe5r4GS3DeZVm5IOIarMlZjo6GoFLLv3dAa/mpCr/j\n3F/6+luKv26ktYRPJXlE7L5AheS/Sx6Vh7+6QIGxqka6dH3xWORHj72+3KDc9XR7nwGMfMxinTdE\nZgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "Output"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "expr1.subs(x, expr1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "podoc": {
     "output_text": "Output"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAABmBAMAAADi/5O6AAAAMFBMVEX///92dnaIiIhUVFSYmJgi\nIiJERES6urpmZmYQEBDMzMwyMjLc3Nzu7u6qqqoAAAA1ApXJAAAAAXRSTlMAQObYZgAAAAlwSFlz\nAA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j2yPpOAyOqY/7kEI8G4+3DqKaD\n3Sc2Exkh1QoeD2pYA8InTMKSZ5JYc2yCRUq0H1QQABOxZNggCsgNbgAz2zpMxjIfZeYgrcKU8KB9\nA5gfv3BWDagPX6Juo0xuPz/GojP62q0JPdcwr4G7zlE3TEymcCkEpsqHGaHtBuLZyldY5dTzCxPX\nuDD30EjzgpjxzDWMKkDAtj+dmnbec/2YBMKofTM0oDAlWaZtu9mxqZyea9MW4YHtPGFmJlIz105P\nwV6abgXGaojFsLvlzIQciYja1pUPTZu6xKL2CZ6sDgTBNE03k0PSghRnkKiNOc9twKSsPLeDfEEW\n8A58DqsatgETsbxyB0my52lnHZfZSAyMvSNtpCwJc9oQB2LqJsdMO0hZghZrJqQYGNvjdxB9xDjd\nogT2+LYAE7XT3ByS7+Y4014ZTNhuZvg2wMTs+4kh80tt3nhKGfE/mospiQ0wVVujEWRKp4tnEEZw\nKrE1GMBjnzCqXcOHgXUeNd6E4Erj5uzs3bdIunT/zffO6t5bIotMNAGs6ZR5Kugs7WJ6KX975hkm\n6gwKAdPnyHB8nhHi+wJgEo4J1BjNZDntGeMels48ff6Pzf/3Hy3vmrn1vn30alphfN45NyGDupeO\npY9uZ44/61XwNuzkA6bLawMbHZpHkmFUqPBOHXib1vP+Ji4D6xoYF14u6f0dZXTdHHLT01iw97e3\nyXW6aODZsbB1tC4liEueqiwP18YRqfN60fUGk5c6S55cr4oDaeNfJFatn+9KawN5LKlNE9FViROn\nsU0ZbVTi32YoG8cTaxNZLC7GE+PS/qKn4WI8sXkthyWtfbj5H0W8ZVg3Xi+nbkyl9kROKHBlKdl7\nUp7St+vO/g8JPEw4WA8K1QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "Output"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "expr1.subs(x, pi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "podoc": {
     "output_text": "9/4"
    }
   },
   "outputs": [
    {
     "data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Ce5UspelJs8g79XeqSlA+/TXKgncWQ9f2F\nP6w/fRzzKdX8Hf38/M7XQDeeNNhPz7Cy+yCaCvMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "9/4"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "expr1.subs(x, S(1) / 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "podoc": {
     "output_text": "2.25000000000000"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAI0AAAA5BAMAAAD5K7X1AAAAMFBMVEX///92dnZERESqqqrMzMyI\niIhmZma6urrc3NwiIiIQEBAyMjJUVFSYmJju7u4AAABC2DRsAAAAAXRSTlMAQObYZgAAAAlwSFlz\nAAAOxAAADsQBlSsOGwAABClJREFUWMOlV01oE0EUnvQv0SSteNGD0Fy8Cal4EUSjHr2kIAieGhBB\nUGjBo4dEL4KI7UlQ0VxU6kFTlFKRavwBQUQSEUHB2lxtkbapaZrdNs/ZzMybt7uzq9B3CLM7b795\n8973vZkw5tjvj6VHs99YoPX/eGHd+VQgb5IP9dPxKTm4BB27GwQTLXfmW1X9qg/qY3KN05ASo+sA\nsxcc1wdmmFgF7Pcf+bw1jO8S/HHvwVr/1R9FABFaT8l2FjrEZ54bcU7AS/7bzVeyCxRH2aZ4lQER\n7zx/NWaA6ZaOST7fNOGIz3tgkskBwB8DTtaSUWS5w1E/jsReUG4szzNQ8NeqNKnSzT+a9OHU5SeV\npq4BqNQTS+jNjvKvvDitIbWbHK5ME6C3tYbDJZ3BBJRENBKGdUGNkfVaPpx0m9GAJxRObP/bW/t2\n6TU2yNIkkTrI1zgmlUiAxy8DNrJrO/fb4as6TOMD38tKAA7fi81wjxi3ay9TuEfcuA8njURiLMLH\ny575Lk1Yxgb5QwBOmRTbYWzbMx8HXewO5WvBOBM6F7BuwGnpZCpR+nAqJJ5ugzISNJ4MFtSHkyfq\nNO0rSskZsq8ISaMpz05uq/+RZ3b5TSGs7iy2Zzf7j7pTG+A4uZB5xufXCM6xt0/PFkydJqCTUV00\nEad/1BGqXfX7GXXq4TbqlA1aZ27EvkPrqM+Py2c1DMfR35DCWbSqYu0Vr1uSSslk81qLCSi+6gx6\n/SndhmwNsKKmewLJmYY1j9sIoZLJeomk+zDyJdwraauhVV8CvXTEqunkP/F2iHoYjMNCPAaiM0Q4\nG16lhWY5Sjqep8oF1zkFdi0MZwHgVUCYOXejCQ2HdypjOI542y4y2+wfZJ4KYtWqi4QpFk7CgCpk\ngDIo76OTL8sBpMhTVXIpD4fiZKHBAnF0M7oWTmUWK0E1cAXAs72/GNp4GPtluEFIGyeyjMN9Fl50\ny9VmrpBL6Ti5FaStUKFzzUy671YknVkdTwLuqbIcMeJUWioDF2uyMbYNeR5Et4G2CSaC67BOSuP0\nUHOug6qxoHDGl004I6i8GKiO1yQ8lErIaIFmpow3X1yn21YHXZvooiGpqj8eNJE2r5UXWVOHfpWc\nMqLbZolwysOmY0srL94QYizN0BvLhKBqivRWScfoh3ea62SdpaZwq7kO2U5sv+q0lRewqeSQ66QR\njKx7w04qmZYfHxA2N3eqDPq2oppK3Poi5g/PfT0v7yP5Nj2tmir32mz/7SntchAliddp+8mpC5m2\nDX0ktvz/bLi9ljTagYQSa0fcbg19E6rruxMxmZh51fUWQXA943Zb1TfFTRxRG1JKEf/5YkV5ypTd\nbuv6+pnC+yq1ArL4nFNLrGvR7abklSxP60xRw35dhJsnP/PlZtjWrFdE8Ixt1Xp23m7N/pQPfwHf\nt5XsjmTLXQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "2.25000000000000"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "_.evalf()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = lambdify(x, expr1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1.,  0.,  1.,  4.,  9.])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "f(np.linspace(-2., 2., 5))"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
